package cn.gjxblog.demo3;

import org.apache.shiro.authc.*;
import org.apache.shiro.realm.AuthenticatingRealm;
import org.apache.shiro.util.ByteSource;

import java.util.UUID;

/**
 * 作用:
 * 作者:gjx
 * 版本:V1.0
 * 创建时间: 2018/7/25 21:48
 */
public class CustomMD5Realm extends AuthenticatingRealm {
    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
        UsernamePasswordToken upToken = (UsernamePasswordToken)token;
        String username = upToken.getUsername();

        //模拟从数据库获取用户信息
        if("xiaohong".equals(username)){
            //参数1 用户名；参数2 md5加密后的密码；参数3 盐；参数4 唯一认证信息id
            return  new SimpleAuthenticationInfo("xiaohong","3d53b73c485f523ef2fe45f2b8dd3c58",ByteSource.Util.bytes("ABCD"),UUID.randomUUID().toString());
        }
        return null;
    }
}
